package com.retail.controller;

import com.retail.entity.CountryOrderReturn;
import com.retail.service.CountryOrderReturnService;
import com.retail.vo.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Comparator;
import java.util.List;

@RestController
@RequestMapping("/api/country_order_return")
@RequiredArgsConstructor
@CrossOrigin
public class CountryOrderReturnController {
    private final CountryOrderReturnService service;

    @GetMapping("/list")
    @Operation(summary = "各国订单量、退货量及退货率关系（按退货率降序）")
    public ResultVO<List<CountryOrderReturn>> list() {
        return ResultVO.ok(service.list()
                .stream()
                .sorted(Comparator.comparing(CountryOrderReturn::getReturnRate))
                .toList());
    }
}
